package com.digiwin.dap.middleware.auth;

/**
 * 存放线程数据
 * @author chenxsa
 */
public final class AppAuthContextHolder {

    private static final ThreadLocal<AppAuthContext> contextHolder = new ThreadLocal();

    AppAuthContextHolder() {
    }

    /**
     * 请空当前线程数据
     */
    public static void clearContext() {
        contextHolder.remove();
    }

    /**
     * 获取当前登录成功的数据
     * @return
     */
    public static AppAuthContext getContext() {
        AppAuthContext ctx= contextHolder.get();
        if (ctx == null) {
            ctx = createEmptyContext();
            contextHolder.set(ctx);
        }
        return ctx;
    }

    /**
     * 设置当前登录的数据
     * @param context
     */
    public static void setContext(AppAuthContext context) {
        contextHolder.set(context);
    }

    /**
     * 创建空的数据
     * @return
     */
    public static AppAuthContext createEmptyContext() {
        return new AppAuthContext();
    }


}
